package com.youi.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.youi.common.Common;
import com.youi.common.DelStatus;
import com.youi.dao.GoodscarDao;
import com.youi.entity.Goods;
import com.youi.entity.Goodsandgoodscar;
import com.youi.entity.Goodscar;
import com.youi.entity.Goodsimgs;
import com.youi.entity.Goodssize;
import com.youi.service.GoodsService;
import com.youi.service.GoodsandgoodscarService;
import com.youi.service.GoodscarService;
import com.youi.service.GoodsimgsService;
import com.youi.service.GoodssizeService;

@Service
public class GoodscarServiceImpl extends BaseServiceImpl<Goodscar> implements GoodscarService{
		
		private GoodscarDao goodscarDao;
		
		@Autowired
		private GoodsandgoodscarService goodsandgoodscarService;
		@Autowired
		private GoodsService goodsService;
		@Autowired
		private GoodsimgsService goodsimgsService;
		@Autowired
		private GoodssizeService goodssizeService;
		@Autowired
		public void setfaultRecordDao(GoodscarDao goodscarDao){
			this.goodscarDao=goodscarDao;
			super.setBaseDAO(goodscarDao);
		}

		@Override
		public void getGoodscarMsg(Goodscar goodscar) {
			// TODO Auto-generated method stub
			if (goodscar!=null) {
				Map<String, Object> prams=new HashMap<String, Object>();
				prams.put(Common.DELSTATUS, DelStatus.NODEL);
				prams.put("goodscarId", goodscar.getId());
				List<Goodsandgoodscar> goodsandgoodscarList=goodsandgoodscarService.getByParams(prams);
				if (goodsandgoodscarList!=null&&goodsandgoodscarList.size()>0) {
					for (Goodsandgoodscar goodsandgoodscar : goodsandgoodscarList) {
						Goods goods=goodsService.get(goodsandgoodscar.getGoodsId());
						if (goods!=null) {
							Map<String, Object> params=new HashMap<String, Object>();
							params.put(Common.DELSTATUS, DelStatus.NODEL);
							params.put("goodsId", goods.getId());
							params.put(Common.TYPE,1);
							Goodsimgs goodsimgs=goodsimgsService.getByParam(params);
							goodsandgoodscar.setGoodsImg(goodsimgs.getImgs());
							params=new HashMap<String, Object>();
							params.put(Common.DELSTATUS, DelStatus.NODEL);
							params.put("goodsId", goods.getId());
							params.put(Common.ID, goodsandgoodscar.getGoodssizeId());
							Goodssize goodssize=goodssizeService.getByParam(params);
							if (goodssize!=null) {
								goodsandgoodscar.setGoodsPeice(goodssize.getPrice());
								goodsandgoodscar.setMaxStockNum(goodssize.getStockNum());
							}
							goodsandgoodscar.setGoods(goods);
						}
					}
				}
				goodscar.setGoodsandgoodscarsList(goodsandgoodscarList);
				
			}
		}
}